package com.hube.platform.tenant.configuration.response;


import com.hube.platform.tenant.constant.StringPool;
import com.hube.platform.tenant.exception.DefaultErrorObject;

import java.io.Serializable;

/**
 * 通用接口请求返回结果
 *
 * @param <T> 泛型对象
 */
public class Response<T> implements Serializable {

    private int code;
    private String message;
    private T data;
    private boolean success;

    @Deprecated
    public void setCode(int code) {
        this.code = code;
    }

    @Deprecated
    public void setMessage(String message) {
        this.message = message;
    }

    @Deprecated
    public void setData(T data) {
        this.data = data;
    }

    @Deprecated
    public void setSuccess(boolean success) {
        this.success = success;
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public T getData() {
        return data;
    }

    public boolean isSuccess() {
        return success;
    }

    public static <E> Response<E> error(int code, String message, E data) {
        return new Response<>(false, code, message, data);
    }

    public static <E> Response<E> error(int code, String message) {
        return new Response<>(false, code, message, null);
    }

    public static <E> Response<E> error(String message) {
        return new Response<>(false, DefaultErrorObject.SYSTEM_SERVER_ERROR.code(), message, null);
    }

    public static <E> Response<E> ok() {
        return new Response<>(true, DefaultErrorObject.OK.code(), StringPool.BLANK, null);
    }

    public static <E> Response<E> ok(E data) {
        return new Response<>(true, DefaultErrorObject.OK.code(), StringPool.BLANK, data);
    }

    public static <E> Response<E> ok(String message, E data) {
        return new Response<>(true, DefaultErrorObject.OK.code(), message, data);
    }

    @Deprecated
    public Response() {

    }

    public Response(boolean success, int code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }

}